package com.gnerv.pabu.basic.core.controller;

import com.gnerv.pabu.basic.core.dto.UpdatePasswordDTO;
import com.gnerv.pabu.basic.core.entity.Result;
import com.gnerv.pabu.basic.core.service.IUserService;
import com.gnerv.pabu.basic.core.utils.ShiroUtils;
import com.gnerv.pabu.basic.core.dto.PersonalDTO;
import com.gnerv.pabu.basic.core.service.IPersonalService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 基础平台-用户 controller 类
 *
 * @author zhang
 * @date 2019/11/30
 **/
@Api(tags = "个人中心")
@Slf4j
@CrossOrigin
@RestController
@RequestMapping("/api/manage/personal")
public class PersonalController {

    @Resource
    private IUserService userService;

    @Resource
    private IPersonalService personalService;

    @ApiOperation("查询 用户 根据用户id")
    @RequestMapping(value = "/select", method = RequestMethod.GET)
    public Result selectUser() {
        PersonalDTO personal = userService.selectPersonal(ShiroUtils.getLoginUser().getUkId());
        return new Result().data("personal", personal);
    }

    @ApiOperation("更新 用户")
    @RequestMapping(value = "/update", method = RequestMethod.POST)
    public Result updateUser(@RequestBody PersonalDTO personalDTO) {
        personalDTO.setUkId(ShiroUtils.getLoginUser().getUkId());
        personalService.updatePersonal(personalDTO);
        return new Result();
    }

    @ApiOperation("更新 用户 密码")
    @RequestMapping(value = "/update/password",method = RequestMethod.POST)
    public Result updatePassword(@RequestBody UpdatePasswordDTO updatePasswordDTO){
        userService.updatePassword(ShiroUtils.getLoginUser().getUkId(), updatePasswordDTO);
        return new Result();
    }

}
